package spe.ui.editor.command;

import org.eclipse.gef.commands.Command;

import spe.model.notation.Link;
import spe.model.notation.SPEMDiagram;
import spe.model.spem.NodeElement;

public class LinkDeleteCommand extends Command
{
	private Link link;
	private SPEMDiagram diagram;
	
	public void setLink(Link l)
	{
		link = l;
		diagram = link.getContainer();
	}
	
	@Override
	public void execute()
	{
		NodeElement source = link.getSource();
		NodeElement target = link.getTarget();
		
		//System.out.println(String.format("[LinkDeleteCommand] %s in diagram %s", link, diagram));
		
		if(source != null)
			source.removeLeavingEdge(link);
		
		if(target != null)
			target.removeArrivingEdge(link);
			
		
		if(diagram != null)
		{
			diagram. removeLink(link);
			link.setContainer(null);
		}
	}
}
